package com.gis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gis.entity.SedimentData;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gis.entity.AvgStationData;
import com.gis.mapper.AvgStationDataMapper;
import com.gis.service.AvgStationDataService;

import java.util.ArrayList;
import java.util.List;

@Service
public class AvgStationDataServiceImpl extends ServiceImpl<AvgStationDataMapper, AvgStationData> implements AvgStationDataService {

    @Override
    public List<AvgStationData> getFromYearAndMonth(int stationId, int fromYear, int fromMonth, int toYear, int toMonth) {
        LambdaQueryWrapper<AvgStationData> queryWrapper = new LambdaQueryWrapper<AvgStationData>()
                .between(AvgStationData::getYear, fromYear, toYear)
                .eq(AvgStationData::getStationId, stationId)
                .orderByAsc(AvgStationData::getYear,AvgStationData::getMonth);
        List<AvgStationData> avgStationDataList = list(queryWrapper);
        List<AvgStationData> result = new ArrayList<>();
        for(AvgStationData avgStationData: avgStationDataList){
            if(avgStationData.getYear()==fromYear && avgStationData.getMonth().compareTo(fromMonth)<0){
                continue;
            }
            if(avgStationData.getYear()==toYear&&avgStationData.getMonth().compareTo(toMonth)>0){
                continue;
            }
            result.add(avgStationData);
        }
        return result;
    }
}
